<template>
  <div id="plan_all">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="search.key"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
        >
          <el-button type="primary" @click="onsubmit"
          >查询
          </el-button
          >
        </el-form-item
        >
      </el-form>
      <el-button class="ebtn" type="warning" @click="GotoPg(null, null)"
      >新增销售合同
      </el-button
      >
    </div>
    <div class="order_table">
      <template>
        <el-table :data="ListData" style=" margin: 10px 20px;width: calc(100% - 40px)"  :height="autoHeightTable" stripe>
          <!-- <el-table-column prop="xuhao" label="序号" align="center"></el-table-column> -->
          <el-table-column label="序号" align="center">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="month"
            label="月份"
            align="center"
          ></el-table-column>  -->
          <el-table-column
            prop="contractNumber"
            label="合同号"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="clientNumber"
            label="客户编号"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="clientName"
            label="客户名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="shengxiaoTime"
            label="生效日期"
            align="center"
          >
            <template v-slot="scope">
              <span>
                {{formatTime(scope.row.shengxiaoTime)}}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="shixiaoTime"
            label="失效日期"
            align="center"
          >
            <template v-slot="scope">
              <span>
                {{formatTime(scope.row.shixiaoTime)}}
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0">错误</span>
              <span v-if="scope.row.status == 1">待审核</span>
              <el-button v-if="scope.row.status == 2" type="text" size="medium"
                         @click="getBOhui(scope.row.checkflowId)">驳回
              </el-button>
<!--              <span v-if="scope.row.status == 2">驳回</span>-->
              <span v-if="scope.row.status == 3">已审核</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="GotoPg(scope.row.id, null)"
                v-show="scope.row.status != 1"
              >编辑
              </el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="GotoPg(scope.row.id, 1)"
              >详情
              </el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="current"
      :page-size="pagesize"
      @current-change="handleCurrentChange"
      :page-count="total"
    >
    </el-pagination>
    <el-dialog
      title="驳回详情"
      :visible.sync="dialogVisible_bohui"
      width="50%"
      :modal-append-to-body="false">
      <ul :data="bohuilist" class="bohuizujian">
        <li>
          <span>审核日期</span>
          <el-input v-model="bohuilist.checkTime" style="width: 70%;" disabled></el-input>
        </li>
        <li>
          <span>审核人</span>
          <el-input v-model="bohuilist.userName" style="width: 70%;" disabled></el-input>
        </li>
        <li>
          <span>驳回理由</span>
          <el-input v-model="bohuilist.bohuiReason" style="width: 70%;" disabled></el-input>
        </li>
      </ul>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="dialogVisible_bohui = false">返 回</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {

    return {
      dialogVisible_bohui: false,
      bohuilist:{
        bohuiReason:"",
        checkTime:"",
        userName:"",
      },
      search: {key: "", start: "", end: ""},
      ListData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      dialogVisible: false,
    };
  },
  computed: {
    autoHeightTable() {
      return document.documentElement.scrollHeight - 251 - 78;
    },
  },
  created() {
    this.getList();
  },
  methods: {
    getBOhui(checkflowId) {
      this.dialogVisible_bohui = true
      axios("/JX_java/procurement/getCheckFlowDetails?checkFlowId=" + checkflowId).then((res) => {
        console.log(res)
        let relse = res.data.data
        this.bohuilist = relse
        console.log(this.bohuilist)
      })


    },
    //时间格式化
    formatTime(data){
      return data==null?"":data.substring(0, 10);
    },
    //获取
    getList() {
      const json = {
        beginTime: this.search.start,
        endTime: this.search.end,
        key: this.search.key,
        pageNum: this.current ,
        pageSize: this.pagesize,
      };
      const message = JSON.parse(localStorage.getItem("message"));
      axios
        .post(
          "/JX_java/sales/contract/getContractList?userId=" + message.Id,
          json
        )
        .then((res) => {
          const relse = res.data.data.content
          this.ListData = relse;
          console.log(relse,11111111111111111111111)
          this.total= res.data.data.totalPages
        });
    },
    onsubmit() {
      this.getList();
    },
    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = "";
        this.search.end = "";
      }
    },

    // 分页
    handleCurrentChange(e) {
      this.current=e
      this.getList();
    },

    // //新增订单计划 编辑 与 详情
    GotoPg(id, edit) {
      if (id === null) {
        this.$router.push({
          path: "/SaleContractsAdd",
          query: {id: id, edit: edit},
        });
      } else if (id != null) {
        this.$router.push({
          path: "/SaleContractsBj",
          query: {id: id, edit: edit},
        });
      }

    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";

#plan_all .search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
   margin: 0 20px;
  //margin-bottom: 10px;
}

#plan_all .demo-form-inline {
  display: inline-block;
}

#plan_all .el-pagination {
  margin-top: 15px;
  text-align: center;
}

#plan_all .ebtn {
  float: right;
  margin-right: 20px;
}
.bohuizujian{
  display: flex;
  flex-wrap: wrap;
  li{
    width: 33%;
    padding-top: 10px;
    text-align: center;
    span{
      display: inline-block;
      width: 25%;
    }
  }
}
</style>
